package es.ruido4design.pfc.complete;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class CompleteClasses {

	public static void main(String[] args) throws Exception {
		final String rootPath = "/home/victormerino/Dropbox/UOC/TFC/Workspace/tfc-bd/src/main/java/edu/uoc/vmerinom/tfc/domain/";
		final File directory = new File(rootPath);
		final String[] list = directory.list();
		for (final String string : list) {
			if (string.contains(".java")) {
				final File java = new File(rootPath + string);
				final FileReader fr = new FileReader(java);
				final BufferedReader br = new BufferedReader(fr);
				String line = br.readLine();
				final List<String> javaFile = new ArrayList<String>();
				while (line != null) {
					// line = line.replaceAll(", catalog = \"test\"", "");
					line = line
							.replaceAll(
									"java.io.Serializable \\{",
									"java.io.Serializable \\{ /** Default Serial Version ID */ private static final long serialVersionUID = 1L;");
					line = line.replaceAll("HashSet", "ArrayList");
					line = line.replaceAll("Set", "List");
					// line = line.replaceAll(
					// "@Temporal\\(TemporalType.TIMESTAMP\\)", "");
					// line = line.replaceAll(
					// "import javax.persistence.Temporal;", "");
					// line = line.replaceAll(
					// "import javax.persistence.TemporalType;", "");
					// line = line.replaceAll("import java.util.Date;",
					// "import java.sql.Timestamp;");
					// line = line.replaceAll("Date ", "Timestamp ");
					javaFile.add(line);
					line = br.readLine();
				}

				br.close();
				fr.close();

				final FileWriter fw = new FileWriter(java);
				final PrintWriter pw = new PrintWriter(fw);
				for (final String code : javaFile) {
					pw.println(code);
				}

				pw.close();
				fw.close();
			}
		}
	}
}
